<?php
class Blog extends Vfriend_Db {	
	var $cache;
	var $clear;
	var $notify;
	var $behaviour;
	var $mlogs;
	public function __construct() {
		$this->cache 		= new Vfriend_Cache();
		$this->clear 		= $this->cache->clear;
		$this->notify 		= new Notification();
		$this->behaviour	= new Behaviour();
		$this->mlogs		= new Mlogs();
	}
	public function add($intUserId, $strImage, $strTitle, $strContent, $strShort, $strLinkMusic, $intPerm, $intBthemId=0) {
		try {			
			$this->prepare('call blogs_add(?,?,?,?,?,?,?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $strImage, PDO::PARAM_STR, 150);
			$this->bindParam(3, $intBthemId, PDO::PARAM_INT, 11);
			$this->bindParam(4, $strTitle, PDO::PARAM_STR, 255);
			$this->bindParam(5, $strContent, PDO::PARAM_STR);
			$this->bindParam(6, $strShort, PDO::PARAM_STR, 500);
			$this->bindParam(7, $strLinkMusic, PDO::PARAM_STR, 1000);
			$this->bindParam(8, $intPerm, PDO::PARAM_INT, 4);			
			$arrResult 	= $this->fetchAll();			
			$intBlogId  = isset($arrResult[0]['blogid']) ? $arrResult[0]['blogid'] : 0;
			if($intBlogId) {
				$this->clear->deleteBlog($intUserId);
				if($intPerm < 3) {
					$objVfriendUser = new Vfriend_User();
					$arrRelation	= $objVfriendUser->getRelation($intUserId,2);
					if($arrRelation) {
						$strContent = Zend_Json::encode(
											array(	'posterid'=>$intUserId,
													'blogid'=>$intBlogId,
													'title'=>$strTitle,
													'content'=>$strShort,
												)
									);
						foreach($arrRelation as $value) {
							$this->notify->insert($value,40,$strContent,$intBlogId);
							$this->mlogs->insert($value,30,$strContent);
							$this->logBehaviour($value,$intUserId,$intUserId,11,$intBlogId);
						}
					}
					$this->logBehaviour($intUserId,$intUserId,$intUserId,11,$intBlogId);
				}
			}
			return $intBlogId;
		} catch(Exception $e) {
			Vfriend_Function::logDb('Blog::add - ' .$e->getMessage());			
			return null;
		}
	}
	public function update($intUserId, $intBlogId, $strImage, $strTitle, $strContent, $strShort, $strLinkMusic, $intPerm, $intAcmt, $intBthemId=0) {
		try {				
			$this->prepare('call blogs_update(?,?,?,?,?,?,?,?,?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intBlogId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $strImage, PDO::PARAM_STR, 150);
			$this->bindParam(4, $intBthemId, PDO::PARAM_INT, 11);
			$this->bindParam(5, $strTitle, PDO::PARAM_STR, 255);
			$this->bindParam(6, $strContent, PDO::PARAM_STR);
			$this->bindParam(7, $strLinkMusic, PDO::PARAM_STR, 1000);						
			$this->bindParam(8, $intPerm, PDO::PARAM_INT, 4);			
			$this->bindParam(9, $intAcmt, PDO::PARAM_INT, 4);		
			$this->bindParam(10, $strShort, PDO::PARAM_STR, 500);			
			$arrResult 	= $this->fetchAll();			
			$intError  	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {
				$strImage = isset($arrResult[0]['image']) ? $arrResult[0]['image'] : '';
				if($strImage != '') {
					$this->deleteImg(0,$strImage);
				}
				$this->clear->deleteBlog($intUserId);
				$this->clear->deleteBlogById($intBlogId);
			}
			return $intError;
		} catch(Exception $e) {
			Vfriend_Function::logDb('Blog::update - ' .$e->getMessage());			
			return null;
		}
	}
	public function updateImg($intUserId, $intBlogId) {
		try {
			
			$this->prepare('call blogs_update_img(?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intBlogId, PDO::PARAM_INT, 11);
			$arrResult	= $this->fetchAll();
			$intError  	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {
				$strImage	= isset($arrResult[0]['image']) ? $arrResult[0]['image'] : 0;
				$this->deleteImg($intBlogId, $strImage);
				$this->clear->deleteBlog($intUserId);
				$this->clear->deleteBlogById($intBlogId);				
			}
			return $intError;
		} catch(Exception $e) {
			Vfriend_Function::logDb('Blog::update - ' .$e->getMessage());			
			return null;
		}
	}
	public function delete($intUserId, $intBlogId) {
		try {			
			$this->deleteImg($intBlogId);
			$this->prepare('call blogs_delete(?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intBlogId, PDO::PARAM_INT, 11);;			
			$arrResult 	= $this->fetchAll();			
			$intError  	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {
				$this->clear->deleteBlog($intUserId);
				$this->clear->deleteBlogById($intBlogId);	
				$this->notify->deleteByType(40,$intBlogId);
				$this->notify->deleteByType(42,$intBlogId);
				$this->behaviour->deleteBySrcId(1,$intBlogId);
			}
			return $intError;
		} catch(Exception $e) {
			Vfriend_Function::logDb('Blog::delete - ' .$e->getMessage());			
			return null;
		}
	}
	public function get($intBlogId) {
		try {
			$strKey 	= BLOG_GET . $intBlogId;
			$arrResult	= $this->cache->get($strKey);
			if(!Vfriend_Function::isCached($arrResult)) {
				$this->prepare('call blogs_get(?)');
				$this->bindParam(1, $intBlogId, PDO::PARAM_INT, 11);
				$arrResult = $this->fetchAll();
				$this->cache->set($strKey, $arrResult, BLOG_GET_EXPIRE);
			}
			return isset($arrResult[0]) ? $arrResult[0] : null;
		} catch(Exeception $e) {
			Vfriend_Function::logDb('Blog::get - ' .$e->getMessage());			
			return null;
		}
	}
	public function getRss() {
		try {
			$strKey 	= BLOG_GETRSS;
			$arrResult	= $this->cache->get($strKey);
			if(!Vfriend_Function::isCached($arrResult)) {
				$this->prepare('call blogs_getall_rss()');
				$arrResult = $this->fetchAll();
				$this->cache->set($strKey, $arrResult, BLOG_GETRSS_EXPIRE);
			}
			return isset($arrResult) ? $arrResult : null;
		} catch(Exeception $e) {
			Vfriend_Function::logDb('Blog::getRss - ' .$e->getMessage());			
			return null;
		}
	}
	public function getAll($intUserId, $intType, $strValue, $intOff, $intLimit, &$intTotal=0) {
		try {				
			$arrResult	= null;
			$strKey		= '';
			if($intOff == 0) {
				if($strValue == '' && $intType != 2 && $intType != 5) {
					$strKey = BLOG_GETALL . $intType;
				}
				if($intType == 2 || $intType == 5) {
					$strKey = BLOG_GETALL . $intType . $intUserId;
				}
				if($strKey != '') $arrResult = $this->cache->get($strKey);
			}
			if(!Vfriend_Function::isCached($arrResult)) {
				$this->prepare('call blogs_getall(?,?,?,?)');
				$this->bindParam(1, $intType, PDO::PARAM_INT, 11);
				$this->bindParam(2, $strValue, PDO::PARAM_STR);
				$this->bindParam(3, $intOff, PDO::PARAM_INT, 11);
				$this->bindParam(4, $intLimit, PDO::PARAM_INT, 4);		
				$arrResult 	= $this->fetchAll();
				if($strKey != '') {
					$this->cache->set($strKey, $arrResult, BLOG_GETALL_EXPIRE);
				}
			}
			$intTotal	= isset($arrResult[0]['foundRows']) ? $arrResult[0]['foundRows'] : 0;
			return isset($arrResult) ? $arrResult : null;
		} catch(Exception $e) {
			Vfriend_Function::logDb('Blog::getAll - ' .$e->getMessage());			
			return null;
		}
	}
	public function getAllByUser($intUserId, $strStart, $strEnd, $strValue, $intOff, $intLimit, &$intTotal=0) {
		try {	
			$arrResult	= null;
			if($intOff == 0 && $strValue == '' && $strStart == '' && $strEnd == '') {
				$strKey 	= BLOG_GETALLBYUSER . $intUserId;						
				$arrResult = $this->cache->get($strKey);
			}
			if(!Vfriend_Function::isCached($arrResult)) {
				$this->prepare('call blogs_getall_user(?,?,?,?,?,?)');
				$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
				$this->bindParam(2, $strStart, PDO::PARAM_STR, 10);
				$this->bindParam(3, $strEnd, PDO::PARAM_STR, 10);
				$this->bindParam(4, $strValue, PDO::PARAM_STR);
				$this->bindParam(5, $intOff, PDO::PARAM_INT, 11);
				$this->bindParam(6, $intLimit, PDO::PARAM_INT, 4);		
				$arrResult 	= $this->fetchAll();
				if($intOff == 0 && $strValue == '' && $strStart == '' && $strEnd == '') {
					$this->cache->set($strKey, $arrResult, BLOG_GETALLBYUSER_EXPIRE);
				}
			}
			$intTotal	= isset($arrResult[0]['foundRows']) ? $arrResult[0]['foundRows'] : 0;
			return isset($arrResult) ? $arrResult : null;
		} catch(Exception $e) {
			Vfriend_Function::logDb('Blog::getAllByUser - ' .$e->getMessage());			
			return null;
		}
	}
	public function getAllByRelation($intUserId, $strFriend, $intBlogId, $strTitle, $intOff, $intLimit) {
		try {				
			$strKey 	= BLOG_GETALLBYRELATION . $intUserId . $intBlogId;		
			$arrResult  = $this->cache->get($strKey);
			if(!Vfriend_Function::isCached($arrResult)) {				
				$this->prepare('call blogs_getall_relative(?,?,?,?,?,?)');
				$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
				$this->bindParam(2, $strFriend, PDO::PARAM_STR);
				$this->bindParam(3, $intBlogId, PDO::PARAM_INT, 11);
				$this->bindParam(4, $strTitle, PDO::PARAM_STR, 255);
				$this->bindParam(5, $intOff, PDO::PARAM_INT, 11);
				$this->bindParam(6, $intLimit, PDO::PARAM_INT, 4);		
				$arrResult 	= $this->fetchAll();
				$this->cache->set($strKey, $arrResult, BLOG_GETALLBYRELATION_EXPIRE);
			}
			return isset($arrResult) ? $arrResult : null;
		} catch(Exception $e) {
			Vfriend_Function::logDb('Blog::getAllByRelation - ' .$e->getMessage());			
			return null;
		}
	}
	public function getSearch($intUserId, $strKeyword, $strFriend, $intOff, $intLimit, &$intTotal=0) {
		try {	
			/* echo $intUserId .',\''. $strKeyword .'\',\'' . $strFriend . '\',' . $intOff . ','. $intLimit;
			exit(); */
			$this->prepare('call blogs_search(?,?,?,?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $strKeyword, PDO::PARAM_STR, 50);
			$this->bindParam(3, $strFriend, PDO::PARAM_STR);
			$this->bindParam(4, $intOff, PDO::PARAM_INT, 11);
			$this->bindParam(5, $intLimit, PDO::PARAM_INT, 4);		
			$arrResult 	= $this->fetchAll();
			$intTotal	= isset($arrResult[0]['foundRows']) ? $arrResult[0]['foundRows'] : 0;
			return isset($arrResult) ? $arrResult : null;
		} catch(Exception $e) {
			Vfriend_Function::logDb('Blog::getSearch - ' .$e->getMessage());			
			return null;
		}
	}
	public function getCmtTotal($intBlogId) {
		try {	
			$strKey	   = BLOG_GETCMTTOTAL . $intBlogId;
			$arrResult = $this->cache->get($strKey);
			if(!Vfriend_Function::isCached($arrResult)) {
				$this->prepare('call bcomments_get_total(?)');
				$this->bindParam(1, $intBlogId, PDO::PARAM_INT, 11);	
				$arrResult 	= $this->fetchAll();
				$this->cache->set($strKey, $arrResult, BLOG_GETCMTTOTAL_EXPIRE);
			}
			$intTotal	= isset($arrResult[0]['foundRows']) ? $arrResult[0]['foundRows'] : 0;
			return $intTotal;
		} catch(Exception $e) {
			Vfriend_Function::logDb('Blog::getCmtTotal - ' .$e->getMessage());			
			return null;
		}
	}
	public function getCmtList($intBlogId, $intOffset, $intLimit) {
		try {	
			$this->prepare('call bcomments_getall(?,?,?)');
			$this->bindParam(1, $intBlogId, PDO::PARAM_INT, 11);	
			$this->bindParam(2, $intOffset, PDO::PARAM_INT, 11);	
			$this->bindParam(3, $intLimit, PDO::PARAM_INT, 4);	
			$arrResult 	= $this->fetchAll();
			return isset($arrResult) ? $arrResult : null;
		} catch(Exception $e) {
			Vfriend_Function::logDb('Blog::getCmtList - ' .$e->getMessage());			
			return null;
		}
	}
	public function getTopCmt($intBlogId,$intLimit=BEHAVIOUR_TOP_LIMIT) {
		try {	
			$strKey	 	= BLOG_GETTOPCMT . $intBlogId;
			$arrResult	= $this->cache->get($strKey);
			if(!Vfriend_Function::isCached($arrResult)) {
				$this->prepare('call bcomments_get_top(?,?)');
				$this->bindParam(1, $intBlogId, PDO::PARAM_INT, 11);	
				$this->bindParam(2, $intLimit, PDO::PARAM_INT, 4);	
				$arrResult 	= $this->fetchAll();
				$this->cache->set($strKey, $arrResult, BLOG_GETTOPCMT_EXPIRE);
			}
			return isset($arrResult) ? $arrResult : null;
		} catch(Exception $e) {
			Vfriend_Function::logDb('Blog::getTopCmt - ' .$e->getMessage());			
			return null;
		}
	}
	public function getCmtUser($intBlogId) {
		try {	
			$strKey	 	= BLOG_GETCMTUSER . $intBlogId;
			$arrResult 	= $this->cache->get($strKey);
			if(!Vfriend_Function::isCached($arrResult)) {
				$this->prepare('call bcomments_get_user(?)');
				$this->bindParam(1, $intBlogId, PDO::PARAM_INT, 11);	
				$arrResult 	= $this->fetchAll();
				$this->cache->set($strKey, $arrResult, BLOG_GETCMTUSER_EXPIRE);
			}
			return $arrResult;
		} catch(Exception $e) {
			Vfriend_Function::logDb('Blog::getCmtUser - ' .$e->getMessage());			
			return null;
		}
	}
	public function addComment($intUserId, $intBlogId, $strContent,&$intOwnerId=0) {
		try {
			$this->prepare('call bcomments_add(?,?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intBlogId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $strContent);
			$arrResult	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			$intOwnerId	= isset($arrResult[0]['userid']) ? $arrResult[0]['userid'] : 0;
			if($intError == 0) {				
				$strTitle	= isset($arrResult[0]['title']) ? $arrResult[0]['title'] : '';
				$intCmtId	= isset($arrResult[0]['bcmtid']) ? $arrResult[0]['bcmtid'] : 0;				
				$intCount	= isset($arrResult[0]['icount']) ? $arrResult[0]['icount'] : 0;				
				$this->clear->deleteBlog($intUserId);
				$this->clear->deleteBlog($intOwnerId);
				$this->clear->deleteBlogById($intBlogId);
				$strContentJson = Zend_Json::encode(
														array(	'posterid'	=> $intUserId,
																'ownerid'	=> $intOwnerId,
																'blogid'	=> $intBlogId,
																'title'		=> $strTitle,																
																'cmt'		=> $strContent,
																'lcmt'		=> 0
															)
													);
				$arrUser	= $this->getCmtUser($intBlogId);
				$isHasUser	= 0;
				if($arrUser) {
					$isHasOwner = 0;					
					foreach($arrUser as $value) {
						$intReceiveId = $value['userid'];
						if($intReceiveId == $intOwnerId) {
							$isHasOwner++;
						}
						if($intUserId != $intReceiveId) {
							$this->mlogs->insert($intReceiveId,31,$strContentJson);
							$this->notify->insert($intReceiveId,41,$strContentJson,$intCmtId);							
						}
						$this->logBehaviour($intReceiveId, $intOwnerId, $intUserId, 12, $intBlogId);						
					}
					if(!$isHasOwner && $intUserId != $intOwnerId) {
						$this->mlogs->insert($intOwnerId,31,$strContentJson);
						$this->notify->insert($intOwnerId,41,$strContentJson,$intCmtId);
					}					
				}
				$this->logBehaviour($intOwnerId, $intOwnerId, $intUserId, 12, $intBlogId);
				$this->logBehaviour($intUserId, $intOwnerId, $intUserId, 12, $intBlogId);
			}
			return $intError;
		} catch(Exception $e) {
			Vfriend_Function::logDb('Blog::addComment - ' .$e->getMessage());			
			return null;
		}
	}
	public function deleteComment($intUserId, $intBlogId, $intBcommentId) {
		try {
			$this->prepare('call bcomments_delete(?,?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intBlogId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intBcommentId, PDO::PARAM_INT, 11);
			$arrResult 	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {
				$intOwnerId	= isset($arrResult[0]['userid']) ? $arrResult[0]['userid'] : 0;
				$this->clear->deleteBlog($intUserId);
				$this->clear->deleteBlog($intOwnerId);
				$this->clear->deleteBlogById($intBlogId);
				$this->notify->deleteByType(41,$intBcommentId);
				$this->notify->deleteByType(43,$intBcommentId);				
			}
			return $intError;
		} catch(Exception $e) {
			Vfriend_Function::logDb('Blog::deleteComment - ' .$e->getMessage());			
			return null;
		}
	}
	public function getLike($intBlogId, $intLimit=BEHAVIOUR_TOP_LIMIT) {
		try {
			$strKey	 	= BLOG_GETLIKE . $intBlogId;
			$arrResult	= $this->cache->get($strKey);			
			if(!Vfriend_Function::isCached($arrResult)) {
				$this->prepare('call blikes_get_top(?,?)');
				$this->bindParam(1, $intBlogId, PDO::PARAM_INT, 11);	
				$this->bindParam(2, $intLimit, PDO::PARAM_INT, 4);	
				$arrResult 	= $this->fetchAll();
				$this->cache->set($strKey, $arrResult, BLOG_GETLIKE_EXPIRE);
			}
			return isset($arrResult) ? $arrResult : null;
		} catch(Exception $e) {
			Vfriend_Function::logDb('Blog::getLike - ' . $e->getMessage());
			return null;
		}
	}
	public function addLike($intUserId, $intBlogId, &$intLike=0) {
		try {
			$this->prepare('call blikes_add(?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intBlogId, PDO::PARAM_INT, 11);			
			$arrResult 	= $this->fetchAll();
			$intError 	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {
				$intOwnerId	= isset($arrResult[0]['userid']) ? $arrResult[0]['userid'] : 0;
				$strTitle	= isset($arrResult[0]['title']) ? $arrResult[0]['title'] : '';
				$intLike 	= isset($arrResult[0]['tlike']) ? $arrResult[0]['tlike'] : 0;
				$this->clear->deleteBlog($intUserId);
				$this->clear->deleteBlog($intOwnerId);
				$this->clear->deleteBlogById($intBlogId);
				$strContent = Zend_Json::encode(array(	'posterid'=>$intUserId,
														'ownerid'=>$intOwnerId,
														'blogid'=>$intBlogId,
														'title'=>$strTitle
														));
				$this->notify->insert($intOwnerId,42,$strContent,$intBlogId);
				/* // behaviour				
				$arrUser	= $this->getCmtUser($intBlogId);
				$isHasUser	= 0;
				if($arrUser) {
					$isHasOwner = 0;					
					foreach($arrUser as $value) {
						$intReceiveId = $value['userid'];											
						$this->logBehaviour($intReceiveId, $intOwnerId, $intUserId, 13, $intBlogId);						
					}
				}
				$this->logBehaviour($intOwnerId, $intOwnerId, $intUserId, 13, $intBlogId);
				$this->logBehaviour($intUserId, $intOwnerId, $intUserId, 13, $intBlogId); */
			}
			return $intError;
		} catch(Exception $e) {
			Vfriend_Function::logDb('Blog::addLike - ' . $e->getMessage());
			return null;
		}
	}
	public function addLikeCmt($intUserId, $intBlogId, $intBcommentId, &$intLike=0) {
		try {
			$this->prepare('call bclikes_add(?,?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intBlogId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intBcommentId, PDO::PARAM_INT, 11);
			$arrResult 	= $this->fetchAll();
			$intError 	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {
				$intLike 	= isset($arrResult[0]['tlike']) ? $arrResult[0]['tlike'] : 0;
				$intOwnerId = isset($arrResult[0]['userid']) ? $arrResult[0]['userid'] : 0;
				$intCmtorId = isset($arrResult[0]['cuserid']) ? $arrResult[0]['cuserid'] : 0;
				$strTitle 	= isset($arrResult[0]['title']) ? $arrResult[0]['title'] : '';
				$strCmt 	= isset($arrResult[0]['content']) ? $arrResult[0]['content'] : '';
				$this->clear->deleteBlogById($intBlogId);
				$this->clear->deleteBlog($intOwnerId);
				$strContent = Zend_Json::encode(array(	'posterid'=>$intUserId,
														'ownerid'=>$intOwnerId,
														'blogid'=>$intBlogId,
														'title'=>$strTitle,
														'cmt'=>$strCmt
														));
				$this->notify->insert($intCmtorId,43,$strContent,$intBcommentId);
				// behaviour
				/* $arrUser	= $this->getCmtUser($intBlogId);
				$isHasUser	= 0;
				if($arrUser) {
					$isHasOwner = 0;					
					foreach($arrUser as $value) {
						$intReceiveId = $value['userid'];											
						$this->logBehaviour($intReceiveId, $intOwnerId, $intUserId, 14, $intBlogId);						
					}
				}
				$this->logBehaviour($intOwnerId, $intOwnerId, $intUserId, 14, $intBlogId);
				$this->logBehaviour($intUserId, $intOwnerId, $intUserId, 14, $intBlogId); */
			}
			return $intError;
		} catch(Exception $e) {
			Vfriend_Function::logDb('Blog::addLikeCmt - ' . $e->getMessage());
			return null;
		}
	}
	public function getQuote($intBlogId, $intType) {
		try {
			$strKey	 	= BLOG_GETQUOTE . $intBlogId . $intType;
			$arrResult	= $this->cache->get($strKey);
			if(!Vfriend_Function::isCached($arrResult)) {
				$this->prepare('call blogs_get_quote(?,?)');
				$this->bindParam(1, $intBlogId, PDO::PARAM_INT, 11);	
				$this->bindParam(2, $intType, PDO::PARAM_INT, 4);	
				$arrResult 	= $this->fetchAll();
				$this->cache->set($strKey, $arrResult, BLOG_GETQUOTE_EXPIRE);
			}
			return isset($arrResult[0]) ? $arrResult[0] : null;
		} catch(Exception $e) {
			Vfriend_Function::logDb('Blog::getQuote - ' . $e->getMessage());
			return null;
		}
	}
	public function deleteImg($intBlogId, $strImg='') {
		if($strImg == '') {
			$arrRow = $this->get($intBlogId);
			if(isset($arrRow) && $arrRow) {
				if(isset($arrRow['image']) && $arrRow['image'] != '') {
					if(file_exists(DIR_BLOG_FULL . $arrRow['image']))
						@unlink(DIR_BLOG_FULL . $arrRow['image']);
					if(file_exists(DIR_BLOG_THUMB . $arrRow['image']))
						@unlink(DIR_BLOG_THUMB . $arrRow['image']);
					if(file_exists(DIR_BLOG_SMALL . $arrRow['image']))
						@unlink(DIR_BLOG_SMALL . $arrRow['image']);
				}
			}
		} else {
			if(file_exists(DIR_BLOG_FULL . $strImg))
				@unlink(DIR_BLOG_FULL . $strImg);
			if(file_exists(DIR_BLOG_THUMB . $strImg))
				@unlink(DIR_BLOG_THUMB . $strImg);
			if(file_exists(DIR_BLOG_SMALL . $strImg))
				@unlink(DIR_BLOG_SMALL . $strImg);
		}
	}	
	public function logBehaviour($intUserId,$intOwnerId,$intPosterId,$intType,$intSrcId) {
		$strQueryCore 		= 'get';
		$strQueryLike		= 'getLike';
		$strQueryTotalCmt	= 'getCmtTotal';
		$strQueryCmt		= 'getTopCmt';		
		$strQueryQuote		= 'getQuote';
		$this->behaviour->insert($intUserId,
								 $intOwnerId,
								 $intPosterId,
								 $strQueryCore,
								 $strQueryLike,
								 $strQueryTotalCmt,
								 $strQueryCmt,
								 $strQueryQuote,
								 $intType,
								 $intSrcId);
	}
}
?>